package SwordForOffer.Problem12;

public class MyPointMaxOfNDigits {
    public void printToMaxOfNDigits1(int n) {
        if (n < 1){
            return;
        }
        int[] arr = new int[n];
        boolean start;
        arr[arr.length - 1] = 1;
        while(arr[0] < 10){

            start = false;
            for (int i = 0;i < n;i++){

                if (arr[i] != 0 || start){
                    start = true;
                    System.out.print(arr[i]);
                }
            }
            System.out.println();
            arr = arrNumAdd(arr);

        }

    }

    private int[] arrNumAdd(int[] arr) {
        boolean isIn = false;
        int level = arr.length - 1;
        arr[level] ++;
        while (level >= 0){
            if (isIn){
                arr[level] ++;
                isIn = false;
            }
            if (arr[level] > 9 && level > 0){
                arr[level] -= 10;
                isIn = true;
            }
            level --;
        }



        return arr;
    }

    public void printToMaxOfNDigits2(int n) {
        int[] array=new int[n];
        if(n<=0)
            return;
        printArray(array, 0);
    }

    private void printArray(int[] array,int n) {
        if (n == array.length){
            boolean isFirstNo0 = false;
            for(int j=0;j<array.length;j++) {
                if(array[j]!=0 || isFirstNo0) {
                    System.out.print(array[j]);
                    isFirstNo0=true;
                }
            }
            System.out.print("\n");
            return;
        }
        for (int i = 0; i < 10; i++) {
            array[n] = i;
            printArray(array, n + 1);
        }

    }
}
